package com.cencat.common.exception;

import com.cencat.common.constant.CommonConstants;
import lombok.Getter;

/**
 * 业务异常类
 * 用于处理业务逻辑中的异常情况
 */
@Getter
public class BusinessException extends RuntimeException {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 错误码
     */
    private final Integer code;
    
    /**
     * 错误消息
     */
    private final String message;
    
    /**
     * 异常数据
     */
    private final Object data;
    
    public BusinessException(String message) {
        super(message);
        this.code = CommonConstants.ERROR_CODE;
        this.message = message;
        this.data = null;
    }
    
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
        this.data = null;
    }
    
    public BusinessException(Integer code, String message, Object data) {
        super(message);
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.code = CommonConstants.ERROR_CODE;
        this.message = message;
        this.data = null;
    }
    
    public BusinessException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.data = null;
    }
    
    /**
     * 快速创建业务异常
     * @param message 错误消息
     * @return 业务异常
     */
    public static BusinessException of(String message) {
        return new BusinessException(message);
    }
    
    /**
     * 快速创建业务异常
     * @param code 错误码
     * @param message 错误消息
     * @return 业务异常
     */
    public static BusinessException of(Integer code, String message) {
        return new BusinessException(code, message);
    }
    
    /**
     * 快速创建业务异常
     * @param code 错误码
     * @param message 错误消息
     * @param data 异常数据
     * @return 业务异常
     */
    public static BusinessException of(Integer code, String message, Object data) {
        return new BusinessException(code, message, data);
    }
}